package demo1;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-03-25
 * Time: 10:52
 */
class Person {
    public String name;
    public int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Test2 {
    public static void main9(String[] args) {
        String str = "hello world hello gu";
        //str[0] = 'w';字符串不可变性
        final int[] arr = {1,2,3,45};//被final修饰只代表不能改变他引用的对象，不代表对象中的值不能改
        arr[0] = 0;
    }

    public static void main(String[] args) {
        String str = "hello";
        String ret1 = str.substring(1);
        System.out.println(ret1);//截取出指定位置开始的剩余字符串
        String ret2 = str.substring(1,3);//[1,3)
        System.out.println(ret2);
        System.out.println("==========");
        String str2 = "  hell oo p j   ";
        System.out.println(str2.trim());//删除字符串首尾的空格
    }
    public static void main7(String[] args) {
        String str = "hello world hello gu";
        String[] ret = str.split(" ");
        for (String value : ret) {
            System.out.println(value);
        }
        String[] ret2 = str.split(" ",2);
        for (String value : ret2) {
            System.out.println(value);
        }
        System.out.println("=============");
        String arr = "195.32.6.5";
        String[] ret3 = arr.split("\\.");
        for (String value : ret3) {
            System.out.println(value);
        }
        String arr2 = "195\\32\\6\\5";
        String[] ret4 = arr2.split("\\\\");
        for (String value : ret4) {
            System.out.println(value);
        }
        String arr3 = "195=32\\6.5";
        String[] ret5 = arr3.split("=|\\\\|.");
        for (String value : ret5) {
            System.out.println(value);
        }
        String str2 = "name=gu&age=12";
        String[] string = str2.split("&");
        for (String value : string) {
            String[] s = value.split("=");
            for (String value2:
                 s) {
                System.out.println(value2);
            }
        }
    }
    public static void main6(String[] args) {
        String str1 = "sihdosldk,abbahab";
        System.out.println(str1);
        String ret = str1.replaceFirst("si","152");
        System.out.println(ret);
        String ret2 = str1.replaceAll("ab","152");
        System.out.println(ret2);
        String ret3 = str1.replace("ab","152");
        System.out.println(ret3);
        String ret4 = str1.replace('s','y');
        System.out.println(ret4);

    }
    public static void main5(String[] args) {
        String str1 = "hello";
        String ret = str1.toUpperCase();
        System.out.println(str1.toUpperCase());
        System.out.println(ret);
        char[] chars  = str1.toCharArray();
        System.out.println(Arrays.toString(chars));
        String ret2 = String.format("%d,%d",1,3);
        System.out.println(ret2);
        int[] arr = {1,2,3,4,5};
        int ret3 = add(arr);
        System.out.println(ret3);
    }
    public static int add(int... args) {
        int ans = 0;
        for (int arg : args) {
            ans += arg;
        }
        return ans;
    }
    public static void main4(String[] args) {
        String s1 = String.valueOf(1234);
        System.out.println(s1);
        String s2 = String.valueOf(new Person("g",15));
        System.out.println(s2);
        System.out.println("===============");
        int date = Integer.valueOf("123");
        int date2 = Integer.parseInt("123");
        //int date3 = Integer.valueOf("aabs");//不能将字母转化
        System.out.println(date);
        System.out.println(date2);

    }
    public static void main3(String[] args) {
        String str1 = "hello";
        char ch = str1.charAt(2);
        System.out.println(ch);
        System.out.println(str1.indexOf('l'));
        System.out.println(str1.indexOf('l',3));
        System.out.println(str1.indexOf("lo"));
        System.out.println(str1.lastIndexOf('l'));
    }
    public static void main2(String[] args) {
        String str1 = new String("hello");
        String str2 = new String("hello");
        String name1 = "gu";
        String name2 = "gu";
        System.out.println(str1 == str2);//比较的是变量的地址

        System.out.println(name1 == name2);
        System.out.println(str1.equals(str2));
        System.out.println(name1.equals(name2));
        System.out.println("========================");
        String str3 = "abc";
        String str4 = "aBc";
        System.out.println(str3.compareTo(str4));
        System.out.println(str3.compareToIgnoreCase(str4));

    }
    public static void main1(String[] args) {
        String name = "gu";
        String name1 = new String("gu");
        char[] chars = {'a','a','b','c'};
        String str = new String(chars);
        System.out.println(str);
        System.out.println(str.length());
        String str1 = "";
        System.out.println(str1.isEmpty());//str1指向的对象中有没有数据

    }
}
